<template>
	<view>
		<up-no-network @disconnected="disconnected" @connected="connected" @retry="retry"></up-no-network>
		<view class="u-content">
			<view class="u-content__circle">
				<up-icon name="checkbox-mark" color="#fff" size="30"></up-icon>
			</view>
			<text class="u-content__normal">网络正常</text>
		</view>
	</view>
</template>

<script>
	export default {
		onLoad() {
			this.retry();
		},
		onShow() {
			wx.hideHomeButton(); // 隐藏返回首页按钮
		},
		methods: {
			refreshCurrentPage() {
				const currentPage = getCurrentPages().pop();
				if (currentPage) {
					currentPage.onLoad();
				}
			},
			toIndex() {
				uni.switchTab({
					url: "/pages/index/index"
				});
			},
			disconnected() {
				console.log('disconnected');
			},
			connected() {
				console.log('connected');
				this.toIndex()
			},
			retry() {
				console.log('retry');
				wx.getNetworkType({
					success: (res) => {
						console.log('当前网络状态：', res.networkType);
						if (res.networkType === 'none') {
							this.refreshCurrentPage();
						} else {
							this.toIndex()
						}
					},
					fail: (err) => {
						console.error('获取网络状态失败:', err);
						this.refreshCurrentPage();
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.u-content {
		padding: 150px 60px 0;
		@include flex(column);
		align-items: center;
		justify-content: center;

		&__circle {
			background-color: $u-success;
			@include flex;
			border-radius: 100px;
			width: 60px;
			height: 60px;
			align-items: center;
			justify-content: center;
		}

		&__normal {
			font-size: 15px;
			color: $u-success;
			margin-top: 15px;
		}
	}
</style>